package com.example.hospitalmanagement.utils

import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.ViewGroup
import android.view.Window
import android.widget.FrameLayout
import android.widget.TextView
import com.bigkoo.pickerview.builder.TimePickerBuilder
import com.bigkoo.pickerview.view.TimePickerView
import com.example.hospitalmanagement.R
import java.text.SimpleDateFormat
import java.util.*

/**
 * 年月日三级联动弹窗
 */
class DataDialog {
    companion object {
        @SuppressLint("SimpleDateFormat")
        fun setDateDialog(context: Context, textView: TextView) {
            val selectedDate: Calendar = Calendar.getInstance()
            val startDate: Calendar = Calendar.getInstance()
            startDate.set(2013, 0, 1)
            val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd")
            val endDate: Calendar = selectedDate
            val tvTime: TimePickerView? = TimePickerBuilder(context) { date, _ ->
                textView.text = simpleDateFormat.format(date)
            }
                .setType(booleanArrayOf(true, true, true, false, false, false))
                .setDate(selectedDate)
                .setTitleBgColor(context.getColor(R.color.white))
                .setRangDate(startDate, endDate)
                .isDialog(true)
                .setLabel("", "", "", "", "", "")
                .setCancelColor(context.getColor(R.color.text_color))
                .build()
            val mDialog: Dialog = tvTime!!.dialog
            val layoutParams = FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                Gravity.BOTTOM
            )
            layoutParams.leftMargin = 0
            layoutParams.rightMargin = 0
            tvTime.dialogContainerLayout.layoutParams = layoutParams
            val dialogWindow: Window? = mDialog.window
            if (null != dialogWindow) {
                dialogWindow.setWindowAnimations(com.bigkoo.pickerview.R.style.picker_view_slide_anim)
                dialogWindow.setGravity(Gravity.BOTTOM)
            }
            tvTime.show()
        }
    }
}